package org.poem.order.controller;

import cn.hutool.core.date.DateUtil;
import org.poem.common.response.CommonResult;
import org.poem.order.entity.Payment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author poem
 */
@RequestMapping("/v1/order")
@RestController
public class OrderController {

    private static final String PAYMENT_URL = "http://localhost:8001/v1/payment/create";

    @Autowired
    private RestTemplate restTemplate;

    /**
     *
     * @param payment
     * @return
     */
    @RequestMapping("/create")
    public CommonResult<Payment> create(@RequestBody  Payment payment){
       return restTemplate.postForEntity(PAYMENT_URL, payment, CommonResult.class).getBody();
    }

    @GetMapping("/getFeignInterface")
    public CommonResult<String> getFeignInterface(){
        return new CommonResult<String>(DateUtil.formatDateTime(new Date()));
    }

}
